<?php

class Button extends AppModel {

    public $label = 'Botones';
    public $displayField = 'description';
    public $plugin = 'Admin';
    public $hasAndBelongsToMany = array('Admin.Rol');
    public $validate = array(
        'refresh' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'El refresco es requerido'
            )
        ),
        'icon' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'El ícono es requerido'
            )
        ),
        'url' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'La url es requerida'
            )
        ),
        'description' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'La descripción es requerida'
            )
        ),
        'status' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'El estado es requerido'
            )
        ),
        'query' => array(
            'selectQuery' => array(
                'rule' => array('selectQueryOnly'),
                'allowEmpty' => true,
                'message' => 'La query SQL solo puede ser de consulta (SELECT)'
            )
        )
    );
    
    public static function selectQueryOnly($check) {
		$value = array_values($check);
        $value = strtoupper($value[0]);
        return preg_match('/^SELECT |^[\s]*$/', $value);
	}

}